﻿using System.Linq;
using WeBlog.Interfaces;
using WeBlog.Repositories;

namespace WeBlog.Models
{
    public class TagViewModel : GridModel<Post>
    {
        public Tag Tag;
        
        public TagViewModel( IUnitOfWork unitOfWork, GridSettings settings, string name ) 
            : base(settings)
        {
            var repository = new TagRepository(unitOfWork);
            Tag = repository.FindByName(name);
            if (Tag == null) throw new NotFoundException();
        }

        public override IQueryable<Post> GetSuperSet()
        {
            return Tag.Posts.Where(x => x.Published == true).OrderByDescending(x => x.PublishDate).AsQueryable();
        }
    }
}